﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VB.Common.Helpers
{
    public static class HTMLHelper
    {
        /// <summary>
        /// Removes all HTMl tags from the source 
        /// Function is made based on investigations described here
        /// http://www.dotnetperls.com/remove-html-tags
        /// </summary>
        /// <param name="sourceHTML">Source HTML code</param>
        /// <returns>Input source without HTML tags</returns>
        public static string RemoveHTMLTags(String sourceHTML)
        {
            char[] array = new char[sourceHTML.Length];
            int arrayIndex = 0;
            bool inside = false;

            for (int i = 0; i < sourceHTML.Length; i++)
            {
                char let = sourceHTML[i];
                if (let == '<')
                {
                    inside = true;
                    continue;
                }
                if (let == '>')
                {
                    inside = false;
                    continue;
                }
                if (!inside)
                {
                    array[arrayIndex] = let;
                    arrayIndex++;
                }
            }
            return new string(array, 0, arrayIndex);
        }
    }
}
